<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="UTF-8" />
<title>广告投放管理</title>
<link rel="stylesheet" type="text/css" href="../Public/jquery-easyui-1.3.4/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../Public/jquery-easyui-1.3.4/themes/icon.css">
<script type="text/javascript" src="../Public/jquery-easyui-1.3.4/jquery.min.js"></script>
<script type="text/javascript" src="../Public/jquery-easyui-1.3.4/jquery.easyui.min.js"></script>

<script charset="utf-8" src="js/kindeditor-4.1.5/kindeditor.js"></script>
<script charset="utf-8" src="js/kindeditor-4.1.5/lang/zh_CN.js"></script>
		
<script language="javascript" type="text/javascript" src="js/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="ajax.php?act=channelpid&1384016856"></script>
 
<script type="text/javascript">
 
$(document).ready(function(){
	$('#mytable').datagrid({
		nowrap: false,
		striped: true,
		url:'index.php?s=/Adpush/indexjson',
		loadMsg:'数据正在加载，请稍候...',
		columns:[[
			{field:'table_pushid',checkbox:true},
			{field:'table_id',title:'投放ID',width:80,align:"left"},
			
			{field:'table_channel',title:'所属频道',width:120,align:"left",formatter:function(value){
				return value.channelname;
			}},
			{field:'table_adplace',title:'广告位名称',width:120,align:"left",formatter:function(value){
				return value.adplacename;
			}},
			{field:'table_adplace',title:'广告位ID',width:120,align:"left",formatter:function(value){
				return value.adplaceid;
			}},
			
			{field:'table_type',title:'广告位类型',width:80,align:"left",formatter:function(value){
				return value.typename;
			}},
			{field:'table_width',title:'宽',width:30,align:"center",formatter:function(value){
				var value = value ? value+'px' : '0px';
				return value;
			}},
			{field:'table_height',title:'高',width:30,align:"center",formatter:function(value){
				var value = value ? value+'px' : '0px';
				return value;
			}},
			 
			 
			{field:'table_status',title:'状态',width:50,align:"left",formatter:function(value){
				if(value=='1'){
					return '<font color=red>删除</font>';
				}else if(value=='2'){
					return '<font color=#FFCC00>禁用</font>';
				}else{
					return '正常';
				}
			}}
		]],
		singleSelect:true,
		fit:true,
		pagination:true,
		pageSize:20,
		toolbar:[{
			text:'新增广告投放',
			iconCls:'icon-add',
			handler:addAction
		},'-',{
			text:'编辑广告投放',
			iconCls:'icon-edit',
			handler:editAction
		},'-',{
			text:'关闭广告投放',
			iconCls:'icon-edit',
			handler:disableAction
		},'-',{
			text:'开始广告投放',
			iconCls:'icon-edit',
			handler:enableAction
		},'-',{
			text:'删除广告投放',
			iconCls:'icon-remove',
			handler:removeAction
		}]
		
	});
	
	function disableAction(){
	var selected = $('#mytable').datagrid('getSelected');
	if(!selected){
		$.messager.alert('错误消息','请先选择一个广告位再禁用！','error');
	}else{
		$.messager.confirm('提示消息','确认禁用？',function(r){
			if(r){
				$.post(window.location.href,'submit=disable&form_id='+selected.table_id,function(data){
					if(data.status=='false'){
						$.messager.alert('错误消息',data.msg,'error');
					}else{
						$.messager.alert('提示消息',data.msg,'info',function(){
							$("#mytable").datagrid('reload');
						});
					}
				},"json");
			}
		});
	}
}
function enableAction(){
	var selected = $('#mytable').datagrid('getSelected');
	if(!selected){
		$.messager.alert('错误消息','请先选择一个广告位再取消禁用！','error');
	}else{
		$.messager.confirm('提示消息','确认取消禁用？',function(r){
			if(r){
				$.post(window.location.href,'submit=enable&form_id='+selected.table_id,function(data){
					if(data.status=='false'){
						$.messager.alert('错误消息',data.msg,'error');
					}else{
						$.messager.alert('提示消息',data.msg,'info',function(){
							$("#mytable").datagrid('reload');
						});
					}
				},"json");
			}
		});
	}
}
	
	
	
	
	
	
	
	
	 //#################初始化定单投放选择界面##########################
	$('#orderTable').datagrid({
		nowrap: false,
		striped: true,
		columns:[[
			{field:'table_pushadplaceid',title:'广告位ID',width:60,align:"center"},
			{field:'table_id',title:'投放ID',width:60,align:"center"},
			{field:'table_orderid',title:'定单ID',width:60,align:"center"},
			{field:'table_adplacename',title:'广告位名称',width:160,align:"center"},
			{field:'table_channelname',title:'所属频道',width:160,align:"center"},
			{field:'table_stime',title:'开始时间',width:140,align:"left"},
			{field:'table_etime',title:'结束时间',width:140,align:"left"},
			
			{field:'table_push',title:'修改投放',width:70,align:"left",formatter:function(value){
				return '<a href="javascript:showmaterialsinfo(\''+value.orderid+'\',\''+value.channelid+'\',\''+value.adplaceid+'\',\''+value.pushchannelid+'\',\''+value.pushadplaceid+'\',\''+value.id+'\')">修改广告</a>';
			}},
			{field:'table_status',title:'状态',width:50,align:"left",formatter:function(value){
				if(value=='1'){
					return '<font color=red>投放</font>';
				}else if(value=='2'){
					return '<font color=#FFCC00>已投放</font>';
				}else{
					return '关闭';
				}
			}}
			 
		]],
		singleSelect:true,
		fit:true,
		pagination:true,
		pageSize:10,
	});
	$('#searchchannelid').combotree({
		width:162,
		treeWidth:160,
		treeHeight:400,
		url:'ajax.php?act=pushchanneltree'
	});
	$('#form_channelid').combotree({
		width:235,
		treeWidth:250,
		treeHeight:400,
		required:true,
		missingMessage:'必选，不能选择存在子级频道的父频道',
		url:'ajax.php?act=pushchanneltree2',
		onSelect:function(){
			$.each(channelPid,function(i,n){
				if(n==$('#form_channelid').combotree('getValue')){
					$.messager.alert('错误消息','不能选择存在子级频道的父频道','error');
					$('#form_channelid').combotree('setValue',{
						id:0,
						text:''
					});
					return;
				}
			});
		}
	});
/*
	$('#searchchannelid').combotree('setValue',{
		id:0,
		text:'顶级频道'
	});
*/	
	$('#searchchannelid').combotree('setValue',0);
	
	$('#form_channelid').combotree('setValue',{
		id:0,
		text:''
	});
	 
	
});







function addAction(){
	$("#form_name").val('');
	$('#form_channelid').combotree('setValue', 0);
	$("#form_typeid").val('0');
	$("#form_width").val('');
	$("#form_height").val(''); 
	$("#materialsinfoWindow").window('setTitle','新增广告位');
	$("#submit").unbind("click");
	$("#submit").bind("click",{action:"<{:U('add')}>"},checkSubmit);
	$("#materialsinfoWindow").window('open');
	$("#showmaterialsinfo").layout('resize');
}
function editAction(){
	var selected = $('#mytable').datagrid('getSelected');
	if(!selected){
		$.messager.alert('错误消息','请先选择一个广告位再编辑！','error');
	}else{
		$("#form_name").val(selected.table_name);
		
		$('#form_channelid').combotree('setValue',selected.table_channel.channelid);
		$("#form_typeid").val(selected.table_type.typeid);
		$("#form_width").val(selected.table_width);
		$("#form_height").val(selected.table_height);
		$("#materialsinfoWindow").window('setTitle','编辑广告位');
		$("#submit").unbind("click");
		$("#submit").bind("click",{action:"<{:U('edit')}>",form_id:selected.table_id},checkSubmit);
		$("#materialsinfoWindow").window('open');
		$("#showmaterialsinfo").layout('resize');
	}
}
function removeAction(){
	var selected = $('#mytable').datagrid('getSelected');
	if(!selected){
		$.messager.alert('错误消息','请先选择一个广告位再删除！','error');
	}else{
		$.messager.confirm('提示消息','确认删除？',function(r){
			if(r){
				$.post('<{:U("remove")}>','form_id='+selected.table_id,function(data){
					if(data.status=='false'){
						$.messager.alert('错误消息',data.info,'error');
					}else{
						$.messager.alert('提示消息',data.info,'info',function(){
							$("#mytable").datagrid('reload');
						});
					}
				},"json");
			}
		});
	}
}
function checkSubmit(event){
	if(!$("#myForm").form('validate')){
		$.messager.alert('错误消息','请确保表单信息无误再提交！','error');
	}else{
		if($("#form_typeid").val()=='0'){
			$.messager.alert('错误消息','请选择广告位类型！','error');
			return;
		}

		closeForm();
		$.post(event.data.action,$('#myForm').serialize()+'&form_id='+event.data.form_id,function(data){
			if(data.status=='false'){
				$.messager.alert('错误消息',data.info,'error');
			}else{
				$.messager.alert('提示消息',data.info,'info',function(){
					$("#mytable").datagrid('reload');
				});
			}
		},"json");
	
	}
}



//
// 显示物料明细
function showorderdetail()
{
	
	$("#searchOrder").window('open');
	$("#OrderLayout").layout('resize');
}












 
function searchres(){
	var searchid = encodeURIComponent($.trim($("#searchid").val()));
	var searchname = encodeURIComponent($.trim($("#searchname").val()));
	var searchchannelid = encodeURIComponent($('#searchchannelid').combotree('getValue'));
	var searchstatus = $("#searchstatus").val();	
	var searchtypeid = $("#searchtypeid").val();	$('#mytable').datagrid({pageNumber:'1',pageSize:'20',url:'ajax.php?act=push_adplace&searchid='+searchid+'&searchname='+searchname+'&searchchannelid='+searchchannelid+'&searchtypeid='+searchtypeid+'&searchstatus='+searchstatus});
}
function undo(){
	$("#searchname").val('');
	$('#searchchannelid').combotree('setValue',{
		id:0,
		text:'顶级频道'
	});
	$("#searchtypeid").val('0');
}


//add
function showmaterialslist(pushadplaceid){
	/* 
	$("#showmaterialslist").load("ajax.php?act=materialslistadplace&pushadplaceid="+pushadplaceid,function(){
		$("#materialslistWindow").window('open');
	});
	*/ 
	$("#pushadplaceid").val(pushadplaceid);
	searchOrder(pushadplaceid);
	$("#searchCustomer").window('open');
	$("#customerLayout").layout('resize');
}

// 显示物料明细
function showmaterialsdetail(pushadplaceid, channelid)
{
	searchOrder2(pushadplaceid, channelid);
	$("#searchCustomer").window('open');
	$("#customerLayout").layout('resize');
}

function selectCustomer(){	//客户查询页面
	undoCustomer();
	searchCustomer();
	$("#searchCustomer").window('open');
	$("#customerLayout").layout('resize');
}

function searchOrder(pushadplaceid){	//客户查询程序
	var orderid = encodeURIComponent($.trim($("#orderid").val()));
	var status = encodeURIComponent($.trim($("#adpstatus").val()));
	if(!pushadplaceid) pushadplaceid = $("#pushadplaceid").val();
	
	$('#orderTable').datagrid({pageNumber:'1',pageSize:'10',url:'ajax.php?act=pushmaterialslistadplace&orderid='+orderid+'&status='+status+'&pushadplaceid='+pushadplaceid});
}

function searchOrder2(pushadplaceid, channelid)
{
	var orderid = encodeURIComponent($.trim($("#orderid").val()));
	var status = encodeURIComponent($.trim($("#adpstatus").val()));
	if(!pushadplaceid) pushadplaceid = $("#pushadplaceid").val();
	
	$('#orderTable').datagrid({pageNumber:'1',pageSize:'10',url:'ajax.php?act=pushmaterialsdetail&orderid='+orderid+'&status='+status+'&channelid='+channelid+'&pushadplaceid='+pushadplaceid});
}


function undoOrder(){	//重置客户查询参数
	$("#orderid").val('');
	$("#adpstatus").val('');
	
}






 
function closeForm(){
	$("#materialsinfoWindow").window('close');
}


function add_time(){
	var num = $("#adtab_num").val();
	num = parseInt(num);
	num++; /* 点击自加 */
	$("#adtab_num").val(num);
	/* clone后先改名，在添加到页面  */
	$("#adtab_1").clone(true).attr("id", "adtab_" + num).attr("nav", num).each(function(){
		$(this).find("input:text").val(""); /* 清空克隆行的数据 */
		$(this).find("#stime").attr({"id":"stime_"+num,"name":"stime[]"});
		$(this).find("#etime").attr({"id":"etime_"+num,"name":"etime[]"});
		$(this).find(".add_button").remove();
		$(this).find(".del_time").attr("onclick","javascript:del_time('"+num+"');").removeAttr("style");
	}).appendTo("#ipt_time_box");
	if(num%2==0){ $("#adtab_"+num).attr("style","background:#e3e3ff;") }
}
function del_time(denum){
	if(confirm("确定要删除吗?") && denum!="1"){
		$("#adtab_" + denum).remove();
	}
}
 
</script>



</head>
<body class="easyui-layout">
<div region="center" title="广告设置-&gt;广告位投放">
<div class="easyui-layout" fit="true">
	<div region="north" border="false" style="height:40px;padding:2px;padding-left:5px;background-color:#DFE8F6;font-size:11px;color:#15428B;"><table><tr><td>广告位ID：</td><td><INPUT TYPE="text" NAME="searchid" id="searchid" style="width:80px;"></td><td>广告位名称：</td><td><INPUT TYPE="text" NAME="searchname" id="searchname" style="width:150px;"></td><td>所属频道：</td><td><SELECT NAME="searchchannelid" id="searchchannelid"></SELECT></td><td>广告位类型：</td><td><SELECT NAME="searchtypeid" id="searchtypeid" style="width:100px"><option value="0">──请选择──</option><option value="12">画中画</option>,<option value="11">特型</option>,<option value="10">摩天楼</option>,<option value="9">图片</option>,<option value="8">伸缩通栏</option>,<option value="7">Button</option>,<option value="6">Banner</option>,<option value="5">富媒体</option>,<option value="4">背投广告</option>,<option value="3">文字链</option>,<option value="2">焦点轮播</option>,<option value="1">通栏</option></SELECT></td>
	<td>广告位状态：</td><td><SELECT NAME="searchstatus" id="searchstatus" style="width:100px"><option value="">─请选择─</option> "><option value="0">正常</option> "><option value="2">禁用</option> "><option value="1">删去</option> </SELECT></td>
	<td><a class="easyui-linkbutton" icon="icon-search" onclick="searchres();">搜索</a>&nbsp;<a class="easyui-linkbutton" icon="icon-undo" onclick="undo();">重置</a></td></tr></table></div>
	<div region="center" border="true"><table id="mytable"></table></div>
</div>
</div>
 
<!--add-->
<div id="materialslistWindow" class="easyui-window" title="订单详情" minimizable="false" collapsible="false" maximizable="false" closed="true" modal="true" style="width:950px;height:500px;padding:0px;">
	<div title="排期规则" style="padding:5px;"><table id="showmaterialslist" border='1' bgcolor=#DFE8F6 cellspacing=0 cellpadding=0 style='color:#333333;font-size:10pt;'></table></div>
</div>
 

<div id="materialsinfoWindow" class="easyui-window" title="修改物料/投放条件" minimizable="false" collapsible="false" maximizable="false" closed="true" modal="true" style="width:800px;height:500px;padding:0px;">
	<div style="padding:5px;" id="showmaterialsinfo">
	
	    
		
	   定单<select NAME="orderidall" id="orderidall" style="width:350px"></select>
	</br>
	 
	
	
	 
	</br>
	
	<input id="adtab_num" name="adtab_num" type="hidden" value="1"/> 	
	<div id="ipt_time_box">
	<div id="adtab_1" nav="1" style="">
	 开始  <input id="stime" name="stime[]"  class="Wdate" type="text" onfocus="WdatePicker({skin:\'whyGreen\',startDate:\'%y-%M-%d 09:10:00\',dateFmt:\'yyyy-MM-dd HH:mm:ss\'})"/> 
	 结束  <input id="etime" name="etime[]" class="Wdate" type="text" onfocus="WdatePicker({skin:\'whyGreen\',startDate:\'%y-%M-%d 09:10:00\',dateFmt:\'yyyy-MM-dd HH:mm:ss\'})"/>
	 <span class="add_button" onclick="javascript:add_time();"><input type="button"  value="添加"  /></span>
	 <span onclick="javascript:del_time();" class="del_time" style="display:none;"><input type="button"  value="删除" /></span>
    </div>
	 </div>
	 </br>
	  
	<textarea name="adcontent" id="adcontent"  style="width:800px;height:400px;visibility:hidden;" ></textarea></div>
	 
	 
	 IP定位 
	  <input id="orderadplacecity" class="mini-treeselect"  multiSelect="true" 
        textField="text" valueField="id" parentField="pid" checkRecursive="true" 
        showFolderCheckBox="true"  expandOnLoad="false" showClose="true" oncloseclick="onCloseClick"
        popupWidth="160"   Width="160" 
    />
	 
	<div>
	
	 
 级别默认广告(优先级别低) &nbsp;&nbsp;<input type="radio" value="0" name="default"  id="default" >关闭 
		<input type="radio"  value="1" name="default" id="default" >开启
		
		
	广告状态 &nbsp;&nbsp;<input type="radio" value="0" name="status"  id="status" >关闭 
		<input type="radio"  value="1" name="status" id="status" >投放
	  <input type="radio"  value="2" name="status" id="status" >已投放&nbsp;&nbsp; 
	
	<a class="easyui-linkbutton" icon="icon-ok" href="javascript:void(0)" id="mysubmit">确定</a>
	<a class="easyui-linkbutton" icon="icon-cancel" href="javascript:void(0)" onclick="closeForm()">取消</a>
	</div>
</div>

<div id="searchOrder" class="easyui-window" title="查找定单投放" minimizable="false" collapsible="false" maximizable="false" closed="true" modal="true" style="width:960px;height:450px;">
	<div class="easyui-layout" fit="true" id="customerLayout">
		<div region="north" border="false" style="height:70px;padding:2px;padding-left:5px;background-color:#DFE8F6;font-size:11px;color:#15428B;"><table><tr><td>定单ID</td>
		<td><input TYPE="text" NAME="orderid" id="orderid" style="width:80px;">
		<input TYPE="hidden" NAME="pushadplaceid" id="pushadplaceid"  >
		</td> 
		<td>
		 
		</td>
		<td><a class="easyui-linkbutton" icon="icon-search" onclick="searchOrder();">搜索</a></td> 
		<td><a class="easyui-linkbutton" icon="icon-undo" onclick="undoCustomer();">重置</a></td></tr></table></div>
		<div region="center" border="true"><table id="orderTable"></table></div>
	</div>
</div>



</body>
</html>